#include "udpWorker.h"
#include <QTimer>

udpWorker::udpWorker(QUdpSocket* socket, const QHostAddress& sender, quint16 senderPort)
    : socket(socket), sender(sender), senderPort(senderPort), m_bIsActive(true){
    setAutoDelete(true);
}

void udpWorker::run(){
    while(m_bIsActive){
        // 例如，回发消息
        QDateTime curDateTime = QDateTime::currentDateTime();
        socket->writeDatagram(curDateTime.toString().toLocal8Bit(), sender, senderPort);
        QThread::msleep(3);
        // 可以添加更多处理逻辑
        if(!m_bIsActive){
            break;
        }
    }
}

void udpWorker::stop(){
    m_bIsActive = false;
}
